from senta import Senta
from htmlParser import MyHTMLParser
from snownlp import SnowNLP
import os


my_senta = Senta()

# 获取目前支持的情感预训练模型, 我们开放了以ERNIE 1.0 large(中文)、ERNIE 2.0 large(英文)和RoBERTa large(英文)作为初始化的SKEP模型
print(my_senta.get_support_model()) # ["ernie_1.0_skep_large_ch", "ernie_2.0_skep_large_en", "roberta_skep_large_en"]

# 获取目前支持的预测任务
print(my_senta.get_support_task()) # ["sentiment_classify", "aspect_sentiment_classify", "extraction"]

# 选择是否使用gpu
use_cuda = True # 设置True or False

# 预测中文句子级情感分类任务
my_senta.init_model(model_class="ernie_1.0_skep_large_ch", task="sentiment_classify", use_cuda=use_cuda)



def file_name(file_dir):
  text=''
  i = 0
  for root, dirs, files in os.walk(file_dir):
    print(root) #当前目录路径
    print(dirs) #当前路径下所有子目录
    print(files) #当前路径下所有非目录子文件
    for file in files:
      if 'md' in file:
        i += 1
        with open(os.path.join(root,file), 'r',encoding='utf-8') as f:
          parser = MyHTMLParser()
          parser.set_totaldata('')
          parser.feed(f.read())
          s=SnowNLP(parser.get_totaldata())
          texts = s.han
          print(texts)
          result = my_senta.predict(texts)
          print(result)
    print(i)
file_name('/home/zx/Senta/waimei/archived/2021-01-09')


